package com.tm.mygsyplayer.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.tm.mygsyplayer.R;

public class CustomVideoPlayer extends StandardGSYVideoPlayer {

    public CustomVideoPlayer(Context context, Boolean fullFlag) {
        super(context, fullFlag);
    }

    public CustomVideoPlayer(Context context) {
        super(context);
    }

    public CustomVideoPlayer(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void changeUiToNormal() {
        super.changeUiToNormal();
        setViewShowState(mTopContainer, INVISIBLE);
        setViewShowState(mBottomContainer, INVISIBLE);
//        //setViewShowState(mStartButton, VISIBLE);
    }

    //    changeUiToPreparingShow
    @Override
    protected void changeUiToPreparingShow() {
        super.changeUiToPreparingShow();
        setViewShowState(mTopContainer, INVISIBLE);
        setViewShowState(mBottomContainer, INVISIBLE);
    }

    @Override
    protected void changeUiToPlayingShow() {
        super.changeUiToPlayingShow();
        setViewShowState(mTopContainer, INVISIBLE);
        setViewShowState(mBottomContainer, INVISIBLE);
    }

    @Override
    protected void touchSurfaceMoveFullLogic(float absDeltaX, float absDeltaY) {
        super.touchSurfaceMoveFullLogic(absDeltaX, absDeltaY);
        //不给触摸快进，如果需要，屏蔽下方代码即可
        mChangePosition = false;

        //不给触摸音量，如果需要，屏蔽下方代码即可
        mChangeVolume = false;

        //不给触摸亮度，如果需要，屏蔽下方代码即可
        mBrightness = false;

    }

    @Override
    protected void touchDoubleUp() {
//        super.touchDoubleUp();
        //不需要双击暂停
    }

    @Override
    protected void touchSurfaceUp() {
        super.touchSurfaceUp();
    }

    @Override
    protected void touchSurfaceMove(float deltaX, float deltaY, float y) {
        super.touchSurfaceMove(deltaX, deltaY, y);
    }

    @Override
    protected void touchSurfaceDown(float x, float y) {
        super.touchSurfaceDown(x, y);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
    }

    @Override
    protected void onClickUiToggle() {
        //super.onClickUiToggle();
        setViewShowState(mTopContainer,INVISIBLE);
        setViewShowState(mBottomContainer,INVISIBLE);

        if (mCurrentState == CURRENT_STATE_NORMAL || mCurrentState == CURRENT_STATE_ERROR) {
            if (isShowNetConfirm()) {
                showWifiDialog();
                return;
            }
            startButtonLogic();
        }else if(mCurrentState == CURRENT_STATE_PLAYING){

            try {
                onVideoPause();
            } catch (Exception e) {
                e.printStackTrace();
            }
            setViewShowState(mStartButton,VISIBLE);
            //setStateAndUi(CURRENT_STATE_PAUSE);
        }else if(mCurrentState == CURRENT_STATE_PAUSE){
            setViewShowState(mStartButton,INVISIBLE);
            if (!mHadPlay && !mStartAfterPrepared) {
                startAfterPrepared();
            }

            try {
                getGSYVideoManager().start();
            } catch (Exception e) {
                e.printStackTrace();
            }
            //setStateAndUi(CURRENT_STATE_PLAYING);

        }else if (mCurrentState == CURRENT_STATE_AUTO_COMPLETE) {
            startButtonLogic();
        }
    }

    @Override
    protected void updateStartImage() {
//        super.updateStartImage();
        if (mStartButton != null) {
            if (mStartButton instanceof ImageView) {
                ImageView imageView = (ImageView) mStartButton;
                if (mCurrentState == CURRENT_STATE_PLAYING) {
                    imageView.setImageResource(R.drawable.ic_video_play);
                } else if (mCurrentState == CURRENT_STATE_ERROR) {
                    imageView.setImageResource(R.drawable.ic_video_play);
                } else {
                    imageView.setImageResource(R.drawable.empty_drawable);
                }
            }
        }

    }

}
